package br.com.moto.web;
 
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;

public class LoginUtils {
         
    public LoginUtils() {
    }
    
    public static String getLoggedUser(){ 
        User user;
                
        try{
            user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        }catch(Exception e){
            user = null;
        }
        
        if(user == null){
            return null;
        }
        return user.getUsername();
    }    
    
}
